% araim - Copied from Strumpen paper so we can alter it later

Stream Hestenes SVD($A[M][N]$ : row major matrix, $R$ : block size)
\begin{algorithmic}
\FOR{$i=1$ to $M$}
  \STATE $S[i] = A[i]^T A[i]$
\ENDFOR
\STATE $\delta = \epsilon \sum_{i=1}^{M}S[i]$
\REPEAT
  \STATE $converged \gets true$
  \FOR{$lb_i=1$ to $M$ by $R$}
    \STATE $ub_i \gets min(lb_i + R, M)$
    \FOR{$lb_j=lb_i$ to $M$ by $R$}
      \STATE $ub_j \gets min(lb_j + R, M)$
      \FOR{$i=lb_i$ to $ub_i$}
        \STATE $S[i] \gets A[i]^T A[i]$
      \ENDFOR
      \FOR{$j=lb_j$ to $ub_j$}
        \STATE $S[j] \gets A[j]^T A[j]$
      \ENDFOR
      \FOR{$i=lb_i$ to $ub_i$}
        \FOR{$j=lb_j$ to $ub_j$}
          \IF{$i < j$}
            \STATE $g \gets A[i]^T A[j]$
              \IF{$|g|> \delta$}
                \STATE $converged \gets false$
              \ENDIF
              \IF{$|g| > \epsilon$}
                \STATE $P[i \mod R][j \mod R].c, P[i \mod R][j \mod R].s \gets jacobi(S[i], S[j], g)$
              \ELSE
                \STATE $P[i \mod R][j \mod R].c, P[i \mod R][j \mod R].s \gets 1, 0$
              \ENDIF
          \ENDIF
        \ENDFOR
      \ENDFOR
      \FOR{$i=lb_i$ to $ub_i$}
        \FOR{$j=lb_j$ to $ub_j$}
          \IF{$i < j$}
            \STATE $c, s = P[i \mod R][j \mod R].c, P[i \mod R][j \mod R].s$
            \FOR{$k = 1$ to $N$}
              \STATE $A[i][k], A[j][k] \gets cA[i][k] - sA[j][k], sA[i][k] + cA[j][k]$
            \ENDFOR
          \ENDIF
        \ENDFOR
      \ENDFOR
    \ENDFOR
  \ENDFOR
\UNTIL{converged = true}
\FOR{$i=1$ to $M$}
  \STATE $\sigma[i] = \sqrt{A[i]^T A[i]}$
\ENDFOR
\end{algorithmic}

